package com.panda.admin.login.access.controller;

import com.panda.admin.login.dto.RoleMenusDto;
import com.panda.admin.login.entity.SystemMenu;
import com.panda.admin.login.access.service.SystemMenuService;
import com.panda.admin.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * author: tcy
 * createDate: 2023/5/11
 * description: 菜单控制
 */
@Api(tags = "菜单控制")
@RestController
@RequestMapping("/menu")
public class SystemMenuController {

    @Autowired
    SystemMenuService systemMenuService;

    @ApiOperation(value = "查询全部菜单")
    @GetMapping("/queryMenus")
    public Result<List<SystemMenu>> queryMenus(){
        return Result.success(systemMenuService.queryMenus());
    }

    @ApiOperation(value = "查询目录和菜单")
    @GetMapping("/queryMenuAndDirect")
    public Result<List<SystemMenu>> queryMenuAndDirect(){
        return Result.success(systemMenuService.queryMenuAndDirect());
    }

    @ApiOperation(value = "根据id查询菜单详情")
    @GetMapping("/queryMenuById/{id}")
    public Result<SystemMenu> queryMenuById(@PathVariable("id") Long id){
        return Result.success(systemMenuService.queryMenuById(id));
    }

    @ApiOperation(value = "增改菜单")
    @PostMapping("/saveOrUpdateMenus")
    public Result<Boolean> saveOrUpdateMenus(@RequestBody SystemMenu systemMenu){
        return Result.success(systemMenuService.saveOrUpdateMenus(systemMenu));
    }

    @ApiOperation(value = "删除菜单")
    @GetMapping("/deleteMenus/{id}")
    public Result<Boolean> deleteMenus(@PathVariable("id") Long id){
        return Result.success(systemMenuService.deleteMenus(id));
    }

    @ApiOperation(value = "根据角色查询菜单")
    @GetMapping("/queryMenusByRole/{roleId}")
    public Result<RoleMenusDto> queryMenusByRole(@PathVariable("roleId") Long roleId){
        return Result.success(systemMenuService.queryMenusByRole(roleId));
    }

}
